package fm.dongman.modellib.source;

import android.app.Activity;

import org.jetbrains.annotations.NotNull;

import fm.dongman.animefm.contractlib.BaseDataSource;
import fm.dongman.animefm.contractlib.IModel;
import fm.dongman.animefm.contractlib.contract.LoginContract;
import fm.dongman.modellib.local.LoginLocalDataSource;
import fm.dongman.modellib.remote.LoginRemoteDataSource;

/**
 * 用户数据操作
 * Created by KUIGE on 2017/10/13.
 */

public class LoginRepository implements LoginContract.ILoginDataSource {
    public static final int TYPE_LOGIN_QQ = LoginContract.ILoginPresenter.Companion.getLOGIN_QQ(); // QQ
    public static final int TYPE_LOGIN_WX = LoginContract.ILoginPresenter.Companion.getLOGIN_WX(); // WX
    public static final int TYPE_LOGIN_SINA = LoginContract.ILoginPresenter.Companion.getLOGIN_SINA(); // WB
    //this实例
    private static LoginRepository INSTANCE;
    //本地用户数据源对象
    private LoginLocalDataSource mLocalSource;
    //网络用户数据源对象
    private LoginRemoteDataSource mRemoteSource;

    /**
     * 返回单例对象
     */
    public static LoginRepository getInstance(LoginRemoteDataSource remoteDataSource, LoginLocalDataSource localDataSource) {
        if (INSTANCE == null) {
            INSTANCE = new LoginRepository(remoteDataSource, localDataSource);
        }
        return INSTANCE;
    }

    private LoginRepository(LoginRemoteDataSource remoteDataSource, LoginLocalDataSource localDataSource) {
        mRemoteSource = remoteDataSource;
        mLocalSource = localDataSource;
    }

    @Override
    public void login(@NotNull String userName, @NotNull String pwd, @NotNull LoadSourceCallback<? super IModel.IUserModel> callback) {
        mRemoteSource.login(userName, pwd, callback);
    }

    @Override
    public void loginSocial(@NotNull Activity activity, int type, @NotNull LoadSourceCallback<? super IModel.IUserModel> callback) {
        mRemoteSource.loginSocial(activity, type, callback);
    }

    @Override
    public void saveData(IModel.IUserModel dataModel) {
        //保存到数据库
        mLocalSource.saveData(dataModel);
    }

    /**
     * 获取数据
     */
    @Override
    public void getData(@NotNull final LoadSourceCallback<? super IModel.IUserModel> callback) {
    }

    @Override
    public void refreshData() {
    }

    @Override
    public void offLine() {
        mRemoteSource.offLine();
    }
}
